package com.jmb.api.controller.project;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jmb.api.common.exception.LeaseException;
import com.jmb.api.common.result.Result;
import com.jmb.api.common.result.ResultCodeEnum;
import com.jmb.api.service.ProjectService;
import com.jmb.api.vo.project.ProjectVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "权限管理")
@RestController
@RequestMapping("project")
public class ProjectController {
    @Autowired
    private ProjectService projectService;
    @Operation(summary = "项目管理新增")
    @PostMapping("save")
    public Result addProject(@RequestBody @Valid ProjectVo projectVo) {
        projectService.saveProject(projectVo);
        return Result.ok();
    }
    @Operation(summary = "项目管理修改")
    @PostMapping("modify")
    public Result modifyProject(@RequestBody @Valid ProjectVo projectVo) {
        projectService.updateProject(projectVo);
        return Result.ok();
    }
    @Operation(summary = "项目管理删除")
    @PostMapping("remove")
    public Result removeProject(Integer projectId) {
        if (projectId == null){
            throw new LeaseException(ResultCodeEnum.WEB_API_ID_NOT_NULL);
        }
        projectService.removeById(projectId);
        return Result.ok();
    }
    @Operation(summary = "项目管理列表")
    @GetMapping("list")
    public Result<IPage<ProjectVo>> getProjectList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, String name,String domain){
        IPage<ProjectVo> page = new Page<>(pageNum,pageSize);
        IPage<ProjectVo> list = projectService.getProjectList(page,name,domain);
        return Result.ok(list);
    }
    @Operation(summary = "项目管理查询")
    @GetMapping("projectId")
    public Result getProjectById(@RequestParam Integer projectId) {
        ProjectVo projectVo = projectService.getProjectById(projectId);
        return Result.ok(projectVo);
    }
}
